package string;

/**
 * String支持正则表达式的方法三:
 * String replaceAll(String regex,String replacement)
 * 将当前字符串中满足正则表达式的部分替换为给定内容
 */
public class ReplaceAllDemo {
    public static void main(String[] args) {
        String line = "abbc123def456ghi";
        //将数字本分替换"NUMBER"
        line = line.replaceAll("[0-9]+","NUMBER");//这儿要有接收返回值
        //因为字符串是不变对象!!!!必须接收新的字符串
        System.out.println(line);

        /*
           和谐用语
         */
        String regex = "(wqnmlgb|cnm|wsnd)";
        String message = "wqnmlgb,我真是cnm的,我是你爹wsnd";
        message = message.replaceAll(regex,"xxx");
        System.out.println(message);
    }
}
